package com.dragon.mmochat.model.gang;

import java.io.Serializable;

import com.dragon.mmochat.model.enumType.MmochatGangMemberType;
import com.dragon.mmochat.service.MmochatMainService;

public class MmochatGangMember implements Serializable,
		Comparable<MmochatGangMember> {
	private static final long serialVersionUID = -6280462852115970486L;
	private int roleId;
	private String name;
	private int bmpId; // 头像
	private MmochatGangMemberType type;
	private int buildValue = 0; // 帮派贡献值
	private int curWeekBuildValue = 0; // 本周贡献值
	private int canUseBuildValue = 0; // 可用贡献值

	public int getRoleId() {
		return roleId;
	}

	public void setRoleId(int roleId) {
		this.roleId = roleId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public MmochatGangMemberType getType() {
		return type;
	}

	public void setType(MmochatGangMemberType type) {
		this.type = type;
	}

	public int getBuildValue() {
		return buildValue;
	}

	public void setBuildValue(int buildValue) {
		this.buildValue = buildValue;
	}

	public int getCurWeekBuildValue() {
		return curWeekBuildValue;
	}

	public void setCurWeekBuildValue(int curWeekBuildValue) {
		this.curWeekBuildValue = curWeekBuildValue;
	}

	public void addBuildValue(int value) {
		curWeekBuildValue += value;
		curWeekBuildValue = Math.max(0, curWeekBuildValue);
		buildValue += value;
		buildValue = Math.max(0, buildValue);
		canUseBuildValue += value;
		canUseBuildValue = Math.max(0, canUseBuildValue);
	}

	public int getBmpId() {
		return bmpId;
	}

	public void setBmpId(int bmpId) {
		this.bmpId = bmpId;
	}

	public int getCanUseBuildValue() {
		return canUseBuildValue;
	}

	public void setCanUseBuildValue(int canUseBuildValue) {
		this.canUseBuildValue = canUseBuildValue;
	}

	public void delCanUseBuildValue(int del) {
		canUseBuildValue -= del;
		canUseBuildValue = Math.max(0, canUseBuildValue);
	}

	@Override
	public int compareTo(MmochatGangMember he) {
		// 在线的排在离线前面
		// 贡献高的排在贡献低的前面
		int myBuildValue = curWeekBuildValue, hisBuildValue = he.getCurWeekBuildValue();
		if (MmochatMainService.players.get(roleId) != null) {
			myBuildValue += 1000000000;
		}
		if (MmochatMainService.players.get(he.getRoleId()) != null) {
			hisBuildValue += 1000000000;
		}

		return myBuildValue - hisBuildValue;
	}

}
